//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.farm.doc.dao.impl;

import com.farm.core.sql.query.DBRule;
import com.farm.core.sql.query.DataQuery;
import com.farm.core.sql.result.DataResult;
import com.farm.core.sql.utils.HibernateSQLTools;
import com.farm.doc.dao.FarmRfDoctypeDaoInter;
import com.farm.doc.domain.FarmDoctype;
import com.farm.doc.domain.FarmRfDoctype;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class FarmRfDoctypeDao extends HibernateSQLTools<FarmRfDoctype> implements FarmRfDoctypeDaoInter {
    @Resource(
        name = "sessionFactory"
    )
    private SessionFactory sessionFatory;

    public FarmRfDoctypeDao() {
    }

    @Transactional
    public void deleteEntity(FarmRfDoctype entity) {
        Session session = this.sessionFatory.getCurrentSession();
        session.delete(entity);
    }

    @Transactional
    public int getAllListNum() {
        Session session = this.sessionFatory.getCurrentSession();
        SQLQuery sqlquery = session.createSQLQuery("select count(*) from farm_rf_doctype");
        BigInteger num = (BigInteger)sqlquery.list().get(0);
        return num.intValue();
    }

    @Transactional
    public FarmRfDoctype getEntity(String id) {
        Session session = this.sessionFatory.getCurrentSession();
        return (FarmRfDoctype)session.get(FarmRfDoctype.class, id);
    }

    @Transactional
    public FarmRfDoctype insertEntity(FarmRfDoctype entity) {
        Session session = this.sessionFatory.getCurrentSession();
        session.save(entity);
        return entity;
    }

    @Transactional
    public void editEntity(FarmRfDoctype entity) {
        Session session = this.sessionFatory.getCurrentSession();
        session.update(entity);
    }

    public Session getSession() {
        return this.sessionFatory.getCurrentSession();
    }

    public DataResult runSqlQuery(DataQuery query) {
        try {
            return query.search(this.sessionFatory.getCurrentSession());
        } catch (Exception var3) {
            return null;
        }
    }

    @Transactional
    public void deleteEntitys(List<DBRule> rules) {
        this.deleteSqlFromFunction(this.sessionFatory.getCurrentSession(), rules);
    }

    @Transactional
    public List<FarmRfDoctype> selectEntitys(List<DBRule> rules) {
        return this.selectSqlFromFunction(this.sessionFatory.getCurrentSession(), rules);
    }

    @Transactional
    public void updataEntitys(Map<String, Object> values, List<DBRule> rules) {
        this.updataSqlFromFunction(this.sessionFatory.getCurrentSession(), values, rules);
    }

    public SessionFactory getSessionFatory() {
        return this.sessionFatory;
    }

    public void setSessionFatory(SessionFactory sessionFatory) {
        this.sessionFatory = sessionFatory;
    }

    @Transactional
    public List<FarmDoctype> getDocTypes(String docId) {
        Session session = this.sessionFatory.getCurrentSession();
        SQLQuery sqlquery = (SQLQuery)session.createSQLQuery("select a.NAME AS NAME,a.TYPEMOD AS TYPEMOD,a.READPOP as READPOP,a.WRITEPOP as WRITEPOP,a.AUDITPOP as AUDITPOP,a.CONTENTMOD AS CONTENTMOD,a.SORT AS SORT,a.TYPE AS TYPE,a.METATITLE AS METATITLE,a.METAKEY AS METAKEY,a.METACONTENT AS METACONTENT,a.LINKURL AS LINKURL,a.ID AS ID,a.CTIME AS CTIME,a.ETIME AS ETIME,a.CUSERNAME AS CUSERNAME,a.CUSER AS CUSER,a.EUSERNAME AS EUSERNAME,a.EUSER AS EUSER,a.PCONTENT AS PCONTENT,a.PSTATE,a.PARENTID,a.TAGS,a.TREECODE,a.DOCNUM,a.QUESTIONNUM,a.TAGSNUM FROM farm_doctype a LEFT JOIN farm_rf_doctype b ON a.ID=b.TYPEID where b.docid=?").addEntity(FarmDoctype.class).setString(0, docId);
        return sqlquery.list();
    }

    protected SessionFactory getSessionFactory() {
        return this.sessionFatory;
    }

    protected Class<FarmRfDoctype> getTypeClass() {
        return FarmRfDoctype.class;
    }

    public FarmDoctype getDocType(String docId) {
        Session session = this.sessionFatory.getCurrentSession();
        SQLQuery sqlquery = (SQLQuery)session.createSQLQuery("select a.NAME AS NAME,a.TYPEMOD AS TYPEMOD,a.READPOP as READPOP,a.WRITEPOP as WRITEPOP,a.AUDITPOP as AUDITPOP,a.CONTENTMOD AS CONTENTMOD,a.SORT AS SORT,a.TYPE AS TYPE,a.METATITLE AS METATITLE,a.METAKEY AS METAKEY,a.METACONTENT AS METACONTENT,a.LINKURL AS LINKURL,a.ID AS ID,a.CTIME AS CTIME,a.ETIME AS ETIME,a.CUSERNAME AS CUSERNAME,a.CUSER AS CUSER,a.EUSERNAME AS EUSERNAME,a.EUSER AS EUSER,a.PCONTENT AS PCONTENT,a.PSTATE,a.PARENTID,a.TAGS,a.TREECODE,a.DOCNUM,a.QUESTIONNUM,a.TAGSNUM FROM farm_doctype a LEFT JOIN farm_rf_doctype b ON a.ID=b.TYPEID where b.docid=?").addEntity(FarmDoctype.class).setString(0, docId);
        List<FarmDoctype> list = sqlquery.list();
        return list.size() > 0 ? (FarmDoctype)list.get(0) : null;
    }
}
